package cn.ekuma.epos.android.util;

import android.content.Context;

import cn.trinea.android.common.entity.CacheObject;
import cn.trinea.android.common.service.Cache;

/**
 * Created by Administrator on 2014/12/16.
 */
public abstract class AbstractCacheAbleQueryOneAsyncTask<T,K>  extends  AbstractQueryOneReturnAsyncTask<T,K>{
    Cache<K,T> cache;
    public AbstractCacheAbleQueryOneAsyncTask(Context c,Cache<K,T> cache)  {
        super(c);
        this.cache=cache;
    }

    public AbstractCacheAbleQueryOneAsyncTask(Cache<K,T> cache) {
        super();
        this.cache=cache;
    }

    @Override
    protected T doInBackground(K... params)
    {
        CacheObject<T> ret=cache.get(params[0]);
        if(ret!=null)
            return ret.getData();
        return super.doInBackground(params);
    }

}
